Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports Bussines.entity
Public Class usuariosDAL
    Private conexion As New conexion
    Public Function listarUsuario(ByVal condicion As String) As DataTable
        Dim cnn As SqlConnection = conexion.abrir()
        Dim cmd As New SqlCommand
        Dim dt As New DataTable
        cmd.Connection = cnn
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "SP_LISTAR_USUARIOS"
        cmd.Parameters.Add(New SqlParameter("@CONDICION", SqlDbType.VarChar, 100)).Value = condicion
        Try
            dt.Load(cmd.ExecuteReader())
            Return dt
        Catch ex As Exception
            Return dt
        Finally
            cmd.Dispose()
            cnn.Close()
        End Try

    End Function

    Public Function listarUsuarioxId(ByVal ID As String) As DataTable
        Dim cnn As SqlConnection = conexion.abrir()
        Dim cmd As New SqlCommand
        Dim dt As New DataTable
        cmd.Connection = cnn
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "[SP_LISTAR_USUARIOS_ID]"
        cmd.Parameters.Add(New SqlParameter("@TRAB_ID", SqlDbType.VarChar)).Value = ID
        Try
            dt.Load(cmd.ExecuteReader())
            Return dt
        Catch ex As Exception
            Return dt
        Finally
            cmd.Dispose()
            cnn.Close()
        End Try

    End Function



    Public Function listarUsuarioTodos(ByVal condicion As String) As DataTable
        Dim cnn As SqlConnection = conexion.abrir()
        Dim cmd As New SqlCommand
        Dim dt As New DataTable
        cmd.Connection = cnn
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "SP_LISTAR_USUARIOS_TODOS"
        cmd.Parameters.Add(New SqlParameter("@CONDICION", SqlDbType.VarChar, 100)).Value = condicion
        Try
            dt.Load(cmd.ExecuteReader())
            Return dt
        Catch ex As Exception
            Return dt
        Finally
            cmd.Dispose()
            cnn.Close()
        End Try

    End Function


    Public Function BuscarActiveDirectory(ByVal trab_id As String) As String
        Dim cnn As SqlConnection = conexion.abrir()
        Dim cmd As New SqlCommand
        Dim dt As New DataTable
        cmd.Connection = cnn
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "sp_buscarCuenta"
        cmd.Parameters.Add(New SqlParameter("@trab_id", SqlDbType.VarChar)).Value = trab_id
        cmd.Parameters.Add(New SqlParameter("@dominio", SqlDbType.VarChar, 100)).Direction = ParameterDirection.Output
        Try
            cmd.ExecuteReader()
            Dim strDominio As String = cmd.Parameters("@dominio").Value.ToString
            cmd.Dispose()
            cnn.Close()
            Return strDominio
        Catch ex As Exception
            Throw ex
        Finally
            
        End Try

    End Function


End Class
